﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Text;
using KPIS.GERP.ESS.DAL;
using KPIS.GERP.ESS.MODEL;

namespace KPIS.GERP.ESS.BLL
{
    public class B_HrmRequest
    {
        private static readonly D_HrmRequest dal = new D_HrmRequest();

        public DataSet GetRequestAbsences(Nullable<int> Sequence, Nullable<int> EmpSequence, string SearchText)
        {
            return dal.GetRequestAbsences(Sequence, EmpSequence, SearchText);
        }
        public int GetAbsenceSequence()
        {
            return dal.GetAbsenceSequence();
        }

        public DataSet GetAbsenceTypes(Nullable<int> Sequence, string SearchText)
        {
            return dal.GetAbsenceTypes(Sequence, SearchText);
        }
        public void InsertAbsence(string AbsenceType, string Employee, DateTime StartDate, string StartTime
                , DateTime EndDate, string EndTime, decimal CountDate, string ContactAddress
                , string ApprovedStatus, string ApprovedBy, string ApprovedPosition
                , Nullable<DateTime> ApprovedDate, Nullable<int> SendSequence, string Remarks, int CreatedBy)
        {
            try
            {
                dal.InsertAbsence(new M_HrmAbsences(0, Int32.Parse(AbsenceType), Int32.Parse(Employee)
                    , StartDate, StartTime, EndDate, EndTime, CountDate
                    , ContactAddress, ApprovedStatus, ApprovedBy, ApprovedPosition, ApprovedDate
                    , SendSequence, Remarks, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }

        public void UpdateAbsence(int Sequence, string AbsenceType, string Employee, DateTime StartDate, string StartTime
                , DateTime EndDate, string EndTime, decimal CountDate, string ContactAddress
                , string ApprovedStatus, string ApprovedBy, string ApprovedPosition
                , Nullable<DateTime> ApprovedDate, string Remarks, int UpdatedBy)
        {

            try
            {
                dal.UpdateAbsence(new M_HrmAbsences(Sequence, Int32.Parse(AbsenceType), Int32.Parse(Employee), StartDate, StartTime, EndDate, EndTime, CountDate
                    , ContactAddress, ApprovedStatus, ApprovedBy, ApprovedPosition, ApprovedDate
                    , (int?)null, Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void UpdateAbsenceStatus(int Sequence, string ApprovedStatus, Nullable<DateTime> ApprovedDate, int UpdatedBy)
        {
            try
            {
                M_HrmAbsences info = new M_HrmAbsences();

                info.Sequence = Sequence;
                info.ApprovedDate = ApprovedDate;
                info.Status = ApprovedStatus;
                info.UpdatedBy = UpdatedBy;

                dal.UpdateAbsenceStatus(info);
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void DeleteAbsence(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.DeleteAbsence(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }

        public DataSet GetRequestChange(Nullable<int> Sequence, Nullable<int> EmpSequence, string SearchText)
        {
            return dal.GetRequestChange(Sequence, EmpSequence, SearchText);
        }
        public void InsertRequestChanges(int EmpSequence, int ChangeType, string Remarks, int CreatedBy)
        {
            try
            {
                dal.InsertRequestChanges(EmpSequence, ChangeType, Remarks, CreatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void UpdateRequestChanges(int Sequence, int ChangeType, string Status, string Remarks, int UpdatedBy)
        {
            try
            {
                dal.UpdateRequestChanges(Sequence, ChangeType, Status, Remarks, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void DeleteRequestChanges(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.DeleteRequestChanges(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
